import java.util.Locale;
import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
        int n = 0;
        String str = "Hello, my name is John";
        String[] ret = str.split(" ");
        for (int i = 0; i < ret.length; i++) {
            if (ret[i] != " ") {
                n++;
            }
        }
        System.out.println(n);
    }

    public boolean isPalindrome(String s) {
        //检测字符串是否为回文
        s = s.toLowerCase(Locale.ROOT);
        char[] array = s.toCharArray();
        int left = 0;
        int right = s.length()-1;

        while (left < right) {
            if (left < right && !isVaildChar(s.charAt(left))) {
                left++;
            }
            //left是有效的字符了
            while (left < right && !isVaildChar(s.charAt(right))) {
                right--;
            }
            //right是有效的字符了
            if (s.charAt(left) != s.charAt(right)) {
                return false;
            }else {
                left++;
                right--;
            }
        }
        return true;
    }

    private boolean isVaildChar(char ch) {
        if (Character.isDigit(ch) || Character.isLetter(ch)) {
            return true;
        }
        return false;
    }
        /*if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'z') {
            return true;
        }
        return false;
    }*/

    //最后一个单词的长度
    public static void main5(String[] args) {
        Scanner scanner = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (scanner.hasNextLine()) { // 注意 while 处理多个 case
            String str = scanner.nextLine();
            int index = str.lastIndexOf(" ");
            String ret = str.substring(index+1);
            System.out.print(ret.length());
        }
    }

    public static int firstUniqChar(String s) {
        //第一个只出现一次的字符
        int[] array = new int[125];
        for(int i = 0;i < s.length();i++) {
            char ch = s.charAt(i);
            array[ch]++;
        }

        for(int i = 0;i < s.length();i++) {
            char ch = s.charAt(i);
            if(array[ch] == 1) {
                return i;
            }
        }
        return -1;
    }

    public static void main4(String[] args) {
        int i = firstUniqChar("adbede");
        System.out.println(i);
    }

    public static void main3(String[] args) {
        StringBuilder stringBuilder = new StringBuilder("abc");

        StringBuffer stringBuffer = new StringBuffer("abc");
        stringBuffer.append("fff");

        System.out.println(stringBuilder);

        stringBuilder.append("132").append(10);
        stringBuilder.append(19.9);
        System.out.println(stringBuilder);//此时不会产生临时对象

        String ret = stringBuilder.toString();
        //stringBuild变成字符串对象

        /*stringBuilder.reverse();//逆制
        System.out.println(stringBuilder);*/
    }

    public static void main2(String[] args) {
        String str = "abc";
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(str);
        stringBuilder.append("abc");
        str = stringBuilder.toString();
        System.out.println(str);
    }

    public static void main1(String[] args) {
        String str = "hello";
        str += "abc";
        /*for (int i = 0; i < 10; i++) {
            str += "abc";不建议在循环当中使用+对字符串进行拼接
        }*/
        System.out.println(str);
    }
}
